<template>
  <div class="alarmConfiguration zy-content">
    <search :columns="searchData" @getSearch="getSearch(arguments)"></search>
    <div class="list-layout mt16">
      <div class="btns clear">
        <span class="title">{{ $t("common.listInformation") }}</span>
        <Button @click="exportTemplateClick">{{
          $t("common.batchExport")
        }}</Button>
      </div>
      <div class="tableContent">
        <Table
          class="resizable-table"
          border
          @on-column-width-resize="onColumnWidthResize"
          :columns="columnsList"
          ellipsis
          ref="selection"
          stripe
          :data="dataArr"
          @on-selection-change="onSelectChange"
        >
          <template slot-scope="{ row }" slot="action">
            <span class="operationBtn" @click="createfaultCodeShowH(row)"
              ><i class="iconfont zy-common-bianji"></i
              >{{ $t("common.Edit") }}</span
            >
            <span class="operationBtn" @click="delPrrShowH(row)"
              ><i class="iconfont zy-common-shanchu"></i
              >{{ $t("common.Delete") }}</span
            >
          </template>
        </Table>
      </div>
      <div class="pageWrap mt16">
        <pageLeftTitle :total="total" :selected="delIds.length" />
        <Page
          :total="total"
          :page-size="pageSize"
          :page-size-opts="pageSizeOption"
          :current="pageNum"
          @on-change="changePageNum"
          @on-page-size-change="changePageSize"
          show-sizer
          show-total
        />
      </div>
    </div>
  </div>
</template>

<script>
import search from "@/components/curd/searchList.vue";
import fileDownload from "js-file-download";
import toggleTableOperation from "@/mixins/toggleTableOperation";
export default {
  name: "rework",
  components: { search },
  mixins: [toggleTableOperation],
  data() {
    return {
      formItem: {},
      addtitle: "",
      searchParams: {},
      pageNum: 1,
      pageSize: 10,
      total: 0,
      searchData: [
        {
          title: "工序",
          key: "productionProcesses",
        },
        {
          title: "车间",
          key: "functionLocation",
          type: "cascader",
          dicUrl: "/basic/organization/findListByToken?level=0",
          params: {
            label: "name",
            value: "code",
            children: "children",
          },
        },
        {
          title: "设备编号",
          key: "equipmentNumber",
        },
        {
          title: "物料编号",
          key: "materialCode",
        },
      ],
      columns: [
        {
          title: "工序",
          key: "productionProcesses",
          minWidth: 130,
          align: "center",
          resizable: true,
        },
        {
          title: "车间",
          key: "functionLocationName",
          minWidth: 130,
          align: "center",
          resizable: true,
        },
        {
          title: "设备编号",
          key: "equipmentNumber",
          minWidth: 130,
          align: "center",
          resizable: true,
        },
        {
          title: "返工单号",
          key: "applicationNumber",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "工单号",
          key: "workOrder",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "物料编号",
          key: "materialCode",
          minWidth: 130,
          align: "center",
          resizable: true,
        },
        {
          title: "物料名称",
          key: "materialName",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "规格型号",
          key: "specificationModel",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "模具编号",
          key: "moldCode",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "返工开始时间",
          key: "reworkStartTime",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "返工结束时间",
          key: "timeEnded",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "返工数量",
          key: "initiationsNumber",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "返工结果",
          key: "processingType",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "数量",
          key: "remainingQuantity",
          minWidth: 150,
          align: "center",
          resizable: true,
        },
        {
          title: "生产时间",
          key: "shiftTime",
          minWidth: 180,
          align: "center",
          resizable: true,
        },
        {
          title: "生产班次",
          key: "shift",
          minWidth: 180,
          align: "center",
          resizable: true,
        },
        {
          title: "返工人",
          key: "initiator",
          minWidth: 180,
          align: "center",
          resizable: true,
        },
        {
          title: "提报时间",
          key: "operateTime",
          minWidth: 180,
          align: "center",
          resizable: true,
        },
        // {
        //     //title: '操作',
        //     title: `${this.$t('common.operation')}`,
        //     slot: "action",
        //     fixed: 'right',
        //     minWidth: 160,
        //     align: "center"
        // }
      ],

      dataArr: [],
      delFaultCodeShowF: false, //是否显示删除弹窗
      pageSizeOption: [10, 20, 30, 40],
      delIds: [],
      selection: [],
    };
  },
  mounted() {
    this.getTableColumnsWidth(this.columns);
    this.searchList();
  },
  methods: {
    getSearch(arg) {
      this.searchParams = JSON.parse(JSON.stringify(arg[0]));
      if (this.searchParams.functionLocation && this.searchParams.functionLocation.length > 0) {
        this.searchParams.functionLocation = [this.searchParams.functionLocation.at(-1)];
      }else delete this.searchParams.functionLocation;
      this.pageNum=1;
      this.searchList();
    },
    reset() {
      this.searchParams = {};
      this.changeNum();
    },
    //分页
    changeNum() {
      this.pageNum = 1;
      this.searchList();
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.searchList();
    },

    changePageNum(val) {
      this.pageNum = val;
      this.searchList();
    },
    //查询列表
    searchList() {
      let params = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        ...this.searchParams,
      };
      this.axios({
        method: "post",
        url: "/dms/rework/getReworkList",
        data: params,
      }).then((res) => {
        if (res.code === 200) {
          this.dataArr = res.data.records;
          this.total = res.data.total;
        } else {
          this.$Message.warning({
            content: res.msg,
            duration: 6,
            closable: true,
          });
        }
      });
    },
    //导出
    exportTemplateClick() {
      let params = {
      };
      for (let key in this.searchParams) {
          if (this.searchParams[key]) {
              this.$set(params, key, this.searchParams[key])
          }
      }
      const filName = "返工执行记录";
      this.axios({
        url: "/dms/rework/export",
        method: "post",
        params: params,
        responseType: "blob",
      }).then((res) => {
        fileDownload(res, filName + ".xls");
      });
    },
  },
};
</script>

<style scoped lang="scss">
.ivu-input-number {
  width: -webkit-fill-available;
}

.row_click {
  cursor: pointer;
  color: rgb(50, 113, 240) !important;
}
</style>
